package com.rmc.verifycode;

import com.rmc.http.accesser.HttpAccesser;
import com.rmc.http.accesser.HttpAccesserParams;
import com.rmc.verifycode.service.parser.OCRVerifyCodeParser;

import java.io.File;

/**
 * User: Hadix
 * Date: 2010-12-6
 * Time: 15:28:14
 */
public class CharGroupTester {
    private static final String[] codeNames =
            {"beijing.verifycode", "guangxi.verifycode",
                    "guizhou.verifycode", "huawei.verifycode",
                    "sichuan.verifycode", "spoa2.verifycode",
                    "spoa1.verifycode", "spoa3.verifycode",
                    "spoa5.verifycode", "heilongjiang.verifycode"};

    public static void test(String imageUrl) throws Exception {
        HttpAccesserParams params = new HttpAccesserParams();
        params.setSoTimeout(2000);
        HttpAccesser accesser = params.createHttpAccesser();
        OCRVerifyCodeParser parser = new OCRVerifyCodeParser("ocr");
        System.out.println("OCR=>" + parser.getCode(imageUrl, accesser));
        for (String codeName : codeNames) {
            CharGroup group = CharGroup.load(codeName);
            File image = accesser.buildReq(imageUrl).submitForFile();
            String code = group.match(image);
            System.out.println(codeName + "=>" + code);
        }
    }

    public static void test(File image) throws Exception{
         for (String codeName : codeNames) {
            CharGroup group = CharGroup.load(codeName);
            String code = group.match(image);
            System.out.println(codeName + "=>" + code);
        }
    }

    public static void main(String[] args) throws Exception {
        test("http://xj.12530.com/sp/imagecache.jsp");
//        test(new File("f:\\Desktop\\2.jpg"));
    }
}
